package 反射和内省;

import java.beans.*;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/8/10.
 */
public class IntrospectorTest {
    public static void main(String[] args) throws IntrospectionException {
        //1、得到目标类的BeanInfo对象
        BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);

        //2.1 得到BeanDescriptor对象及相关信息
        System.out.println("BeanDescriptor===========================");
        BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor();
        System.out.println("类名："+beanDescriptor.getName());
        //2.2 得到PropertyDescriptor对象及相关信息
        System.out.println("PropertyDescriptor===========================");
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor p: propertyDescriptors) {
            String name = p.getName();
            System.out.println("属性名："+name);
        }
        //2.3 得到MethodDescriptor对象及相关信息
        System.out.println("MethodDescriptor===========================");
        MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
        for (MethodDescriptor m: methodDescriptors) {
            Method method = m.getMethod();
            System.out.println("方法名："+method.getName());
        }
    }
}
